package org.example.blog_system.mapper;

import org.apache.ibatis.annotations.*;
import org.example.blog_system.model.BlogInfo;
import org.example.blog_system.model.UserInfo;

import java.util.List;

@Mapper
public interface BlogMapper {
    @Select("select title,content,post_time,blog_id,userid from blog order by post_time desc")
    List<BlogInfo> getList();

    @Select("select title,content,post_time,blog_id,userid from blog where blog_id= #{id}")
    BlogInfo getBlog(@Param("id") Integer blogId);
     @Insert("insert into blog(title, content,userid,post_time) values " +
             "(#{blog.title} , #{blog.content} , #{blog.userid},now())")
    void setBlog(@Param("blog") BlogInfo blogInfo);

     @Update("update blog set " +
             "title=#{blog.title} , content=#{blog.content} ,post_time=now()" +
             " where blog_id=#{blog.blogId}")
    Integer updateBlog(@Param("blog") BlogInfo blogInfo);

     @Delete("delete from blog where blog_id=#{id}")
    Integer deleteBlog(@Param("id") Integer blogId);

    Integer getBlogByUser(@Param("user") UserInfo userInfo);
}
